package com.verisette.ncos.service.master.bizunit;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import org.corp.agi.common.exception.ProcessException;
import org.corp.agi.service.bean.ProcessContext;
import org.corp.agi.service.bean.UserBean;
import org.corp.agi.service.bizunit.CommonBusinessUnit;
import com.verisette.ncos.common.ProjectConstant;
import com.verisette.ncos.persistence.domain.LogUserAccess;
import com.verisette.ncos.persistence.domain.MasterUserGroup;
import com.verisette.ncos.persistence.domain.MasterUserGroupToUserProfile;
import com.verisette.ncos.persistence.domain.MasterUserProfile;

/**
 * {Description here}
 *
 * @author Thippawan Muangchu (Tip)
 * @since Oct 5, 2010 2:11:32 PM
 * @version 1.0.0
 * @see 
 */
@Transactional(propagation=Propagation.REQUIRES_NEW)
public class InquiryUserGroupByUserProfileBU  extends CommonBusinessUnit {
	
	private Logger logger = Logger.getLogger(InquiryUserGroupByUserProfileBU.class);

	@Override
	public void execute(ProcessContext processContext) throws ProcessException {
		List<MasterUserGroup> usgList = null;
		MasterUserProfile userProfile = (MasterUserProfile)processContext.getUserBean();
		
		MasterUserGroupToUserProfile exampleUGP = new MasterUserGroupToUserProfile();
		exampleUGP.setUspId(userProfile.getUspId());
		List<MasterUserGroupToUserProfile> ugpList = (List<MasterUserGroupToUserProfile>)commonDAO.findByExample(exampleUGP);
		if(ugpList!=null && ugpList.size()>0){
			usgList=new ArrayList<MasterUserGroup>();
			for(MasterUserGroupToUserProfile ugp : ugpList){
				MasterUserGroup usg = (MasterUserGroup)commonDAO.findById(MasterUserGroup.class, ugp.getUsgId());
				if(usg!=null){
					usgList.add(usg);
				}
			}
		}
		
		processContext.setValueObject(usgList);
	}

}
